<?php

namespace app\admin\model\yiliao;

use think\Model;


class Pblist extends Model
{

    

    

    // 表名
    protected $name = 'yiliao_pblist';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'weekdata_text',
        'status_text'
    ];
    

    
    public function getWeekdataList()
    {
        return ['11' => __('Weekdata 11'), '12' => __('Weekdata 12'), '21' => __('Weekdata 21'), '22' => __('Weekdata 22'), '31' => __('Weekdata 31'), '32' => __('Weekdata 32'), '41' => __('Weekdata 41'), '42' => __('Weekdata 42'), '51' => __('Weekdata 51'), '52' => __('Weekdata 52'), '61' => __('Weekdata 61'), '62' => __('Weekdata 62'), '01' => __('Weekdata 01'), '02' => __('Weekdata 02')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '0' => __('Status 0')];
    }


    public function getWeekdataTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['weekdata']) ? $data['weekdata'] : '');
        $valueArr = explode(',', $value);
        $list = $this->getWeekdataList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    protected function setWeekdataAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }
	public function doctor(){
		return $this->belongsTo('Doctor', 'yiliao_doctor_id', 'id', [], 'LEFT')->setEagerlyType(0);
	}
	public function shop(){
		return $this->belongsTo('Shop', 'yiliao_shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
	}
}
